{{include template('public/header','admin')}}
<link href="{{STATIC_URL}}/plugins/calendar/calendar.css" rel="stylesheet" type="text/css"/>
<script src="{{STATIC_URL}}/plugins/calendar/calendar.js" type="text/javascript"></script>
<body>
    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <form class="form-horizontal validform" role="form" action="{{url($postUrl)}}" method="post"  id="cpform" name="cpform" onsubmit="return dosub(this)" >
                    <input type='hidden' name='subjectid' value="{{$item['subjectid']}}" />
                    <input type="hidden"name="siteid" value="{{$site.siteid}}" />
                    <input type="hidden"name="from_api" value="" />
                    <div class="form-group">
                        <label for="subject" class="col-sm-2 control-label"><span class="red">*</span>{{L('votesubject_subject')}}</label>
                        <div class="col-sm-10 form-inline">
                            <input type="text" id="subject" name='subject' value="{{$item.subject}}" maxlength="255" tabindex="3" class='form-control' style="width: 320px;"
                                   datatype="*"  nullmsg="请输入{{L('votesubject_subject')}}！" sucmsg="{{L('votesubject_subject')}}验证通过！"  errormsg="请输入{{L('votesubject_subject')}}！" placeholder="请输入{{L('votesubject_subject')}}"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="ischeckbox" class="col-sm-2 control-label">{{L('votesubject_ischeckbox')}}</label>
                        <div class="col-sm-10 form-inline">
                            <select name="ischeckbox" id="ischeckbox"onchange="AdsType(this.value)"  class='form-control'>
                                <option value="0" {{if $item.ischeckbox eq '0'}}selected{{/if}}>单选</option>
                                <option value="1" {{if $item.ischeckbox eq '1'}}selected{{/if}}>多选</option>
                            </select>
                            <input type="button" id="addItem" value="增加选项" class='btn  btn-default'  onclick="add_option()"/>
                        </div>
                    </div>
                    <div class="form-group" id="SizeFormat" style="display: none;">
                        <label for="minval" class="col-sm-2 control-label"></label>
                        <div class="col-sm-10 form-inline">
                            最少选项<input name="minval" type="text" class="form-control"  size="5" style="width: 100;" />项
                            最多选项<input name="maxval" type="text" class="form-control" size="5"  style="width: 100;"/>项
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="option[]" class="col-sm-2 control-label"><span class="red">*</span>投票选项</label>
                        <div class="col-sm-10 form-inline">
                            <div id="option_list_1" class="form-inline" style="line-height: 5;">
                                {{if $action=="修改"}}
                                {{$i=0}}
                                {{foreach $options as $optionid=>$option}}
                                <p  style="display: none;"> {{$i++}}</p>
                                <input type="text" name="option[{{$option['optionid']}}]" value="{{$option['option']}}" size="40" id="opt1" class="form-control" datatype="*"  nullmsg="请输入投票选项！" sucmsg="投票选项验证通过！"  errormsg="请输入投票选项！" placeholder="请输入投票选项" />
                                {{if $i>2}}
                                <input type="button" value="删除"  onclick="del_old({{$option['optionid']}})" class="button"/>
                                {{/if}}
                                {{/foreach}}
                                {{else}}
                                <input type="text" name="option[]" id="option1" size="40" id="opt1" class="form-control" datatype="*"  nullmsg="请输入投票选项！" sucmsg="投票选项验证通过！"  errormsg="请输入投票选项！" placeholder="请输入投票选项" />
                                <input type="text" name="option[]" id="option2"  size="40"id="opt2" class="form-control" datatype="*"  nullmsg="请输入投票选项！" sucmsg="投票选项验证通过！"  errormsg="请输入投票选项！" placeholder="请输入投票选项" />
                                {{/if}}
                            </div>
                            <div id="new_option"></div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="fromdate" class="col-sm-2 control-label"><span class="red">*</span>时间范围</label>
                        <div class="col-sm-10 form-inline">
                            <input type="text" name="fromdate" class="calendar-icon form-control" value="{{$item.fromdate}}" style="width:110px;" onclick="showcalendar(event, this)"
                                   datatype="*"  nullmsg="请输入{{L('votesubject_fromdate')}}！" sucmsg="{{L('votesubject_fromdate')}}验证通过！"  errormsg="请输入{{L('votesubject_fromdate')}}！"   />至
                            <input type="text" name="todate" class="calendar-icon form-control" value="{{$item.todate}}" style="width:110px;" onclick="showcalendar(event, this)"
                                   datatype="*"  nullmsg="请输入{{L('votesubject_todate')}}！" sucmsg="{{L('votesubject_todate')}}验证通过！"  errormsg="请输入{{L('votesubject_todate')}}！"  />
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="description" class="col-sm-2 control-label">{{L('votesubject_description')}}</label>
                        <div class="col-sm-10 form-inline">
                            <textarea name="description" id="description" cols="60"rows="6" class='form-control' >{{$item.description}}</textarea>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="allowview" class="col-sm-2 control-label">{{L('votesubject_allowview')}}</label>
                        <div class="col-sm-10 form-inline">
                            <input name="allowview" type="radio" value="1" checked>允许&nbsp;&nbsp;&nbsp;
                            <input name="allowview" type="radio" value="0" >不允许&nbsp;
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="allowguest" class="col-sm-2 control-label">{{L('votesubject_allowguest')}}</label>
                        <div class="col-sm-10 form-inline">
                            <input name="allowguest" type="radio" value="1" checked> 是&nbsp;&nbsp;&nbsp;
                            <input name="allowguest" type="radio" value="0" >否&nbsp;
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="credit" class="col-sm-2 control-label">{{L('votesubject_credit')}}</label>
                        <div class="col-sm-10 form-inline">
                            <input type="text" id="credit" name='credit' value="{{$item.credit}}" maxlength="255" tabindex="3" class='form-control' />
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="interval" class="col-sm-2 control-label">{{L('votesubject_interval')}}</label>
                        <div class="col-sm-10 form-inline">
                            <input type="text" id="interval" name='interval' value="{{$item.interval}}" maxlength="255" tabindex="3" class='form-control' />
                            N天后可再次投票，0 表示此IP地址只能投一次
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="template" class="col-sm-2 control-label"><span class="red">*</span>{{L('votesubject_template')}}</label>
                        <div class="col-sm-10 form-inline">
                            {{form::select_template('vote_temp', 'vote_','id="template" name="template" datatype="*"',$item.template)}}
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="enabled" class="col-sm-2 control-label">{{L('votesubject_enabled')}}</label>
                        <div class="col-sm-10 form-inline">
                            <input name="enabled" type="radio" value="1" checked> 是&nbsp;&nbsp;&nbsp;
                            <input name="enabled" type="radio" value="0" >否&nbsp;
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-offset-2 col-sm-10">
                            <input type='submit' name='dosubmit' class='btn  btn-default' value='{{L('submit')}}' />
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        function AdsType(adstype) {
        $('#SizeFormat').css('display', 'none');
        if (adstype == '0') {

        } else if (adstype == '1') {
        $('#SizeFormat').css('display', '');
        }
        }
        var i = 1;
        function add_option() {
        //var i = 1;
        var htmloptions = '';
        htmloptions += '<div id=' + i + '><span><br><input type="text" name="option[]" size="40"  value="" class="form-control"  datatype="*"  nullmsg="请输入投票选项！" sucmsg="投票选项验证通过！"  errormsg="请输入投票选项！" placeholder="请输入投票选项" /><input type="button" value="删除"  onclick="del(' + i + ')" class="btn btn-default"/><br></span></div>';
        $(htmloptions).appendTo('#new_option');
        var htmloptions = '';
        i = i + 1;
        }
        function del(o) {
        $("div [id=\'" + o + "\']").remove();
        }
        $(function () {
        $(".validform").Validform({tiptype: 3, label: ".control-label", showAllError: true, ajaxPost:true,
                beforeCheck:function(curform){
                // var layIndex = GB.OpenPop.loading("数据提交中...");
                },
                beforeSubmit:function(curform){
                //var layIndex = GB.OpenPop.loading("数据提交中...");
                },
                callback:function(ret){if (ret.status == 'y'){parent.location.reload(); } else if (data.status == 'n'){layer.msg(ret.info); }}
        });
        });
    </script>
</body>
</html>
